﻿using MediatR;
using ProduceBasicData.Api.Application.Command.Supplier;
using ProduceBasicData.Domain.Material;
using ProduceBasicData.ErrorCode;
using ProduceBasicData.Infrastructure.Interface;

namespace ProduceBasicData.Api.Application.Handler.Supplier
{
    /// <summary>
    /// 供应商下拉框命令处理器
    /// </summary>
    public class GetSupplierDropdownCommandHandler : IRequestHandler<GetSupplierDropdownCommand, ApiResult<List<SupplierModel>>>
    {
        private readonly IBaseRespository<SupplierModel> _supplierRepo;

        public GetSupplierDropdownCommandHandler(IBaseRespository<SupplierModel> supplierRepo)
        {
            _supplierRepo = supplierRepo;
        }

        public Task<ApiResult<List<SupplierModel>>> Handle(GetSupplierDropdownCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<List<SupplierModel>>()
            {
                Code = ApiEnum.Success,
                Msg = "供应商查询成功"
            };
            var suppliers = _supplierRepo.GetAll().Where(x => !x.Isdel).ToList();

            result.Data = suppliers;

            return Task.FromResult(result);
        }
    }
}